package com.example.designpatterns.mediator;
import com.example.designpatterns.mediator.ConcreteMediator;
/**
 * 中介者模式示例
 * 展示中介者模式的使用
 */
public class MediatorDemo {
    public static void main(String[] args) {
        // 创建中介者
        Mediator mediator = new ConcreteMediator();

        // 创建同事对象
        Colleague colleague1 = new ConcreteColleague(mediator, "同事1");
        Colleague colleague2 = new ConcreteColleague(mediator, "同事2");
        Colleague colleague3 = new ConcreteColleague(mediator, "同事3");

        // 注册同事对象
        mediator.register(colleague1);
        mediator.register(colleague2);
        mediator.register(colleague3);

        // 同事之间通过中介者通信
        System.out.println("=== 同事1发送消息 ===");
        colleague1.send("大家好！");

        System.out.println("\n=== 同事2发送消息 ===");
        colleague2.send("你好！");

        System.out.println("\n=== 同事3发送消息 ===");
        colleague3.send("你们好！");
    }
}